Ext.define('PJ.view.evaluationprogress.List', {
    extend: 'AM.default.DefaultList',
    requires: ['AM.default.DefaultSearchForm', 
               'AM.default.DateTime', 
               'AM.default.DefaultDateField',
               'PJ.view.evaluationprogress.UsersList',//已评估人员列表
               'PJ.view.evaluationprogress.AssessProgressList',
               'PJ.view.evaluationprogress.ReportedUserList'//查看已报人数
               ],
    initComponent: function(){
    	var me = this;
        me.columns = [{
            header: '培训班编号',
            dataIndex: 'classCount.classNum',
            width: 90,
			renderer: function(value, metaData, record){
				metaData.tdAttr = 'data-qtip="' + value + '"';
				return value;
			}
        }, {
            header: '培训班问卷名称',
            dataIndex: 'classCount.className',
            flex: 1,
            minWidth: 120,
			renderer: function(value, metaData, record){
				metaData.tdAttr = 'data-qtip="' + value + '"';
				return value;
			}
        }, {
            header: '主办单位',
            dataIndex: 'classCount.sponsorName',
            width: 120,
			renderer: function(value, metaData, record){
				metaData.tdAttr = 'data-qtip="' + value + '"';
				return value;
			}
        }, {
            header: '开班时间',
            dataIndex: 'classCount.beginDate',
            width: 90,
            renderer: function(value, metaData, record){
                return value;
            }
        }, {
            header: '结业时间',
            dataIndex: 'classCount.endDate',
            width: 90,
            renderer: function(value, metaData, record){
                return value;
            }
        }, {
            header: '评估开始时间',
            dataIndex: 'classCount.assessStartTime',
            width: 90,
            renderer: function(value, metaData, record){
                return value;
            }
        }, {
            header: '评估结束时间',
            dataIndex: 'classCount.assessEndTime',
            width: 100,
            renderer: function(value, metaData, record){
                return value;
            }
        }, {
            header: '已评估人数',
            dataIndex: 'classCount.answerUser',
            width: 80,
            renderer: function(value, meta, record){
            	var m=record.get("questionnaireMethod");
            	if(m==1&&value!=0)
            		meta.style = "overflow: hidden;text-overflow: ellipsis;cursor: pointer;color: blue;";
                meta.tdAttr = 'data-qtip="' + value + '" paperID=' + record.get("classId") + ' questionnaireId="' + record.get("questionnaireId") + '" questionnaireMethod="' + record.get("questionnaireMethod") + '"';
                return value;
            },
            listeners: {
                click: function(g, clm){
                	var m=clm.getAttribute("questionnaireMethod");
                	var count=clm.getAttribute('data-qtip');
                	if(m==1&&count!=0){
	                    Ext.create('AM.default.DefaultWindowView', {
	                        title: "查看人员信息",
	                        grid: g,
	                        paperId: clm.getAttribute("paperID"),
	                        answerUserStatus: 1,
	                        searchQuestionnaireId: clm.getAttribute("questionnaireId"),
	                        width: 700,
	                        height: 400,
	                        items: [{
	                        	xtype: 'evaluationUsersList'
	                        }]
	                    }).show();
                	}
                }
            }
        }, {
            header: '未评估人数',
            dataIndex: 'classCount.noAnswerUser',
            width: 80,
            renderer: function(value, meta, record){
            	var m=record.get("questionnaireMethod");
            	if(m==1&&value!=0)
            		meta.style = "overflow: hidden;text-overflow: ellipsis;cursor: pointer;color: blue;";
                meta.tdAttr = 'data-qtip="' + value + '" paperID=' + record.get("classId") + ' questionnaireId="' + record.get("questionnaireId") + '" questionnaireMethod="' + record.get("questionnaireMethod") + '"';
                return value;
            },
            listeners: {
                click: function(g, clm){
                	var m=clm.getAttribute("questionnaireMethod");
                	var count=clm.getAttribute('data-qtip');
                	if(m==1&&count!=0){
	                    Ext.create('AM.default.DefaultWindowView', {
	                        title: "查看人员信息",
	                        grid: g,
	                        paperId: clm.getAttribute("paperID"),
	                        answerUserStatus: 2,
	                        searchQuestionnaireId: clm.getAttribute("questionnaireId"),
	                        width: 700,
	                        height: 400,
	                        items: [{
	                        	xtype: 'evaluationUsersList'
	                        }]
	                    }).show();
	                	}
                }
            }
        },{
            header: '参评率（%）',
            dataIndex: 'nswerPerc',
            width: 90,
            sortable: false,
            renderer: function(value, meta, record){
            	meta.tdAttr = "data-qtip='" + value + "'";
            	return value;
            }
        }];
        me.store = Ext.create('PJ.store.evaluationprogress.List', {
            isLoad: false
        });
        this.loadType = gj_onlineLearning_constant.loadType;//加载方式
        me.callParent(arguments);
    },
    //导出
    onExportClick: function(){
    	var me = this;
        var store = me.getStore();
        var params=store.proxy.extraParams;
        var href=me.store.classDetailsUrl + "?page=-1";
        for(var param in params){
        	if(params[param] === undefined){
        		href+="&"+param+"=";
        	}else{
        		href+="&"+param+"="+params[param];
        	}
        }
    	var records = this.getSelectionModel().getSelection();
        for(i in records){
        	if(isNaN(i)){
        		continue;
        	}
        	href+="&searchClassIds="+records[i].get("classId");
        }
        href = encodeURI(href);
        var atag = Ext.get("exportResume");
        atag.set({
            "href": href
        });
        atag.dom.click();
    },
    /**
     * 查看课程评估进度
     */
    onAssessProgressClick: function(){
    	var me = this;
    	var records = this.getSelectionModel().getSelection();
    	if(records.length > 1){
			Ext.Msg.show({
				title: '提示',
				msg: '只允许操作一条数据！',
				icon: Ext.Msg.WARNING,
				buttons: Ext.Msg.OK
			});
			return;
		}
    	var classId = records[0].get("classId");
    	Ext.create('AM.default.DefaultWindowView',{
    		title: "查看课程评估进度",
    		grid: me,
    		height: 400,
    		width: 600,
    		classId:classId,
    		items:[{
                xtype: 'assessProgressList'
            }]
    	});
    },
    listeners: {
    	selectionchange: function(selModel, selected){
            this.down('#' + this.oldId + "AssessProgress").setDisabled(selected.length === 0);
        },
    	viewready: function(){
    		var me = this;
    		me.addDocked([{
    			dock: 'top',
    			xtype: "searchform",
    			columnCount: 3,
    			fieldDefaults: {
    				labelAlign: 'right',
    				labelWidth: 90
    			},
    			items: [{
    				xtype: "textfield",
    				fieldLabel: '培训班编号',
    				name: "searchClassNum",
    				maxLength: "50",
    				emptyText: "请输入培训班编号"
    			}, {
    				xtype: 'defaultDate',
    				fieldLabel: '评估开始时间',
    				name: 'searchAssessStartTime',
    				id: 'searchAssessStartTime',
    				vtype: 'startLessEndDate',
    				startLessEndDate: {
    					targetCmpId: 'searchAssessEndTime',
    					isStart: true
    				},
    				emptyText: "请输入评估开始时间",
    				labelWidth: 90
    			}, {
    				xtype: 'defaultDate',
    				fieldLabel: '评估结束时间',
    				name: 'searchAssessEndTime',
    				id: 'searchAssessEndTime',
    				vtype: 'startLessEndDate',
    				vtypeText: '结束时间不能早于开始时间！',
    				startLessEndDate: {
    					targetCmpId: 'searchAssessStartTime',
    					isStart: false
    				},
    				emptyText: "请输入评估结束时间",
    				labelWidth: 90
    			}, {
    				xtype: "textfield",
    				fieldLabel: '培训班问卷名称',
    				name: "searchClassName",
    				maxLength: "20",
    				emptyText: "请输入培训班问卷名称",
    				labelWidth: 90
    			}, {
    				xtype: 'defaultDate',
    				fieldLabel: '开班时间',
    				name: 'searchBeginDate',
    				id: 'searchEvaluationClassSD',
    				vtype: 'startLessEndDate',
    				startLessEndDate: {
    					targetCmpId: 'searchEvaluationClassED',
    					isStart: true
    				},
    				emptyText: "请输入开班时间",
    				labelWidth: 90
    			}, {
    				xtype: 'defaultDate',
    				fieldLabel: '结业时间',
    				name: 'searchEndDate',
    				id: 'searchEvaluationClassED',
    				vtype: 'startLessEndDate',
    				vtypeText: '结业时间不能早于开班时间！',
    				startLessEndDate: {
    					targetCmpId: 'searchEvaluationClassSD',
    					isStart: false
    				},
    				emptyText: "请输入结业时间",
    				labelWidth: 90
    			}, {
    				xtype: "textfield",
    				fieldLabel: '主办单位',
    				name: "searchSponsorName",
    				emptyText: "请输入主办单位"
    			}],
    			grid: this
    		}, {
                xtype: 'toolbar',
                dock: 'top',
                displayInfo: true,
                items: [{
                    text: '导出',
                    iconCls: 'deriveIco',
                    itemId: this.oldId + "Export",
                    disabled: false,
                    scope: this,
                    handler: this.onExportClick
                },'-',{
                    text: '查看课程评估进度',
                    iconCls: 'publishIco',
                    itemId: this.oldId + "AssessProgress",
                    disabled: true, 
                    scope: this,
                    handler: this.onAssessProgressClick
                }, "->", this.countSelectPanel]
            }]);
            var store = this.store;
            var params = store.proxy.extraParams;
            var newParams = {};
            Ext.apply(params, newParams);
            store.isLoad = true;
            store.load();
    		// 触发权限过滤事件
    		this.fireEvent("permission", this);
    	}
    }
});
